﻿//===============================================================================
// Microsoft Innovation Centre - Western Europe
// Copyright (c) 2008 Microsoft Corporation. All rights reserved.
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===============================================================================
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious.  No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
//===============================================================================

using System.Windows.Controls.Primitives;
using System.Windows.Data;
using Microsoft.WVB.Framework;
using Microsoft.WVB.Silverlight.Infrastructure;
using System.Windows.Controls;
using System;
using System.Windows;

namespace Microsoft.WVB.UI
{
    public class FullScreenButton : ToggleButton
    {
        public IPlayerModel ViewModel { get; set; }

        public FullScreenButton()
            : base()
        {
            this.DefaultStyleKey = typeof(FullScreenButton);

            if (!System.ComponentModel.DesignerProperties.GetIsInDesignMode(this))
            {
                ViewModel = IoC.GetCreate<IPlayerModel>();
                DataContext = ViewModel;

                Binding checkBinding = new Binding("IsFullScreen");
                checkBinding.Source = ViewModel;
                checkBinding.Mode = BindingMode.TwoWay;

                this.SetBinding(ToggleButton.IsCheckedProperty, checkBinding);
            }
        }

        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
            UpdateVisualState();
        }

        internal virtual void ChangeVisualState(bool useTransitions)
        {
            if (this.IsMouseOver)
            {
                VisualStates.GoToState(this, useTransitions, new String[] { VisualStates.StateMouseOver });
            }
            else
            {
                VisualStates.GoToState(this, useTransitions, new String[] { VisualStates.StateNormal });
            }

            if ((bool)this.IsChecked)
            {
                VisualStates.GoToState(this, useTransitions, new String[] { VisualStates.StateChecked });
            }
            else
            {
                VisualStates.GoToState(this, useTransitions, new String[] { VisualStates.StateUnchecked });
            }
        }

        internal void UpdateVisualState()
        {
            this.UpdateVisualState(true);
        }

        internal void UpdateVisualState(bool useTransitions)
        {
            this.ChangeVisualState(useTransitions);
        }
    }
}
